<template>
  <div class="dialog01-box layout-box">
    <div class="layout-box-header">
      <i class="icon-layout-box-title" />
      弹出框
    </div>

    <div class="layout-box-content">
      <el-button type="success" @click="openHint">提示框</el-button>
      <el-button @click="openConfirm">确认框</el-button>
      <el-button @click="openFormDialog">表单弹框</el-button>
      <el-button @click="openCustomDialog">自定义内容弹框</el-button>
    </div>

    <!--表单框-->
    <component :is="asyncFormDialog" ref="formDialogDom" />
    <!--自定义内容弹框-->
    <component :is="asyncCustomDialog" ref="customDialogDom" />
  </div>
</template>

<script>

export default {
  name: 'Dialog01',
  components: {
    'form-dialog': () => import('./components/formDialog'),
    'custom-dialog': () => import('./components/customDialog')
  },
  data() {
    return {
      dialogFlag: false,
      asyncFormDialog: '',
      asyncCustomDialog: '',
      paramsObj: {}
    }
  },
  computed: {},
  mounted() {

  },
  methods: {
    openHint() {
      // 提示框
      this.$alert('提示框', '标题名称', {
        confirmButtonText: '确定',
        callback: action => {
          console.log(`点击确定后执行的回调`)
        }
      })
    },
    openConfirm() {
      // 确认框
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 确定
        this.$message.success('这是一条消息提示')
        // this.$message({
        //   type: 'success',
        //   message: '删除成功!'
        // });
      }).catch(() => {
        // 取消
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    openFormDialog() {
      // 打开表单弹框
      if (!this.asyncFormDialog) {
        this.asyncFormDialog = 'form-dialog'
        if (!this.$refs.formDialogDom) {
          setTimeout(() => {
            this.$refs.formDialogDom.init({ pid: 1 })
          }, 300)
          return
        }
      }
      this.$refs.formDialogDom.init({ pid: '' })
    },
    openCustomDialog() {
      // 打开自定义内容弹框
      if (!this.asyncCustomDialog) {
        this.asyncCustomDialog = 'custom-dialog'
        if (!this.$refs.customDialogDom) {
          setTimeout(() => {
            this.$refs.customDialogDom.init({ pid: 1 })
          }, 300)
          return
        }
      }
      this.$refs.customDialogDom.init({ pid: '' })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
